﻿using Microsoft.CSharp.Activities;
using System;
using System.Activities;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WFExtended.Twitter.Activities.Designers;

namespace WFExtended.Twitter.Activities
{
    /// <summary>
    /// Returns information allowing the creation of an embedded representation of a Tweet on third party sites.
    /// </summary>
    [ToolboxBitmapAttribute(typeof(EntryPoint), "Resources.TweetsToolbox.bmp")]
    [Designer(typeof(TweetsIDDesigner))]
    [Description("Returns information allowing the creation of an embedded representation of a Tweet on third party sites.")]
    public class GetTweetoEmbed : TwitterOperationInvoker<StatusoEmbed>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="GetTweetoEmbed"/> class.
        /// </summary>
        public GetTweetoEmbed()
            : base("GetTweetoEmbed")
        {
            MaxWidth = new InArgument<int>(new CSharpValue<int>("250"));
            HideMedia = new InArgument<bool>(new CSharpValue<bool>("false"));
            HideThread = new InArgument<bool>(new CSharpValue<bool>("false"));
            OmitScript = new InArgument<bool>(new CSharpValue<bool>("false"));
            Align = new InArgument<string>(new CSharpValue<string>("\"center\""));
            Related = new InArgument<string>(new CSharpValue<string>("\"twitter\""));
        }

        /// <summary>
        /// The  ID of the desired status.
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// The  ID of the desired status.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("The  ID of the desired status.")]
        [RequiredArgument]
        public InArgument<string> ID { get; set; }

        /// <summary>
        /// The URL of the Tweet/status to be embedded.
        /// </summary>
        /// <value>
        /// The URL of the Tweet/status to be embedded.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("The URL of the Tweet/status to be embedded.")]
        public InArgument<string> Url { get; set; }

        /// <summary>
        /// The maximum width in pixels that the embed should be rendered at.
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// The maximum width in pixels that the embed should be rendered at.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("The maximum width in pixels that the embed should be rendered at.")]
        [RequiredArgument]
        public InArgument<int> MaxWidth { get; set; }

        /// <summary>
        /// Specifies whether the embedded Tweet should automatically expand images
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// Specifies whether the embedded Tweet should automatically expand images
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("Specifies whether the embedded Tweet should automatically expand images")]
        [RequiredArgument]
        public InArgument<bool> HideMedia { get; set; }

        /// <summary>
        /// Specifies whether the embedded Tweet should automatically show the original message
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// Specifies whether the embedded Tweet should automatically show the original message
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("Specifies whether the embedded Tweet should automatically show the original message")]
        [RequiredArgument]
        public InArgument<bool> HideThread { get; set; }

        /// <summary>
        /// Specifies whether the embedded Tweet HTML should include a script element pointing to widgets.js
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// Specifies whether the embedded Tweet HTML should include a script element pointing to widgets.js
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("Specifies whether the embedded Tweet HTML should include a script element pointing to widgets.js")]
        [RequiredArgument]
        public InArgument<bool> OmitScript { get; set; }

        /// <summary>
        /// Specifies whether the embedded Tweet should be left aligned, right aligned, or centered in the page.
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// Specifies whether the embedded Tweet should be left aligned, right aligned, or centered in the page.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("Specifies whether the embedded Tweet should be left aligned, right aligned, or centered in the page.")]
        [RequiredArgument]
        public InArgument<string> Align { get; set; }

        /// <summary>
        /// A value for the TWT related parameter.
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        ///A value for the TWT related parameter.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("A value for the TWT related parameter.")]
        [RequiredArgument]
        public InArgument<string> Related { get; set; }

        /// <summary>
        /// Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
        /// <code>
        ///  Example Values: en
        /// </code>
        /// </summary>
        /// <value>
        /// Language code for the rendered embed.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("Language code for the rendered embed.")]
        public InArgument<string> Lang { get; set; }

        /// <summary>
        /// Caches the metadata.
        /// </summary>
        /// <param name="metadata">The metadata.</param>
        protected override void CacheMetadata(System.Activities.NativeActivityMetadata metadata)
        {
            RuntimeArgument idArgument = new RuntimeArgument("ID", typeof(string), ArgumentDirection.In, true);
            metadata.Bind(ID, idArgument);
            metadata.AddArgument(idArgument);

            RuntimeArgument urlArgument = new RuntimeArgument("Url", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(Url, urlArgument);
            metadata.AddArgument(urlArgument);

            RuntimeArgument maxWidthArgument = new RuntimeArgument("MaxWidth", typeof(int), ArgumentDirection.In, true);
            metadata.Bind(MaxWidth, maxWidthArgument);
            metadata.AddArgument(maxWidthArgument);

            RuntimeArgument hideMediaArgument = new RuntimeArgument("HideMedia", typeof(bool), ArgumentDirection.In, true);
            metadata.Bind(HideMedia, hideMediaArgument);
            metadata.AddArgument(hideMediaArgument);

            RuntimeArgument hideThreadArgument = new RuntimeArgument("HideThread", typeof(bool), ArgumentDirection.In, true);
            metadata.Bind(HideThread, hideThreadArgument);
            metadata.AddArgument(hideThreadArgument);

            RuntimeArgument omitScriptArgument = new RuntimeArgument("OmitScript", typeof(bool), ArgumentDirection.In, true);
            metadata.Bind(OmitScript, omitScriptArgument);
            metadata.AddArgument(omitScriptArgument);

            RuntimeArgument alignArgument = new RuntimeArgument("Align", typeof(string), ArgumentDirection.In, true);
            metadata.Bind(Align, alignArgument);
            metadata.AddArgument(alignArgument);

            RuntimeArgument relatedArgument = new RuntimeArgument("Related", typeof(string), ArgumentDirection.In, true);
            metadata.Bind(Related, relatedArgument);
            metadata.AddArgument(relatedArgument);

            RuntimeArgument langArgument = new RuntimeArgument("Lang", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(Lang, langArgument);
            metadata.AddArgument(langArgument);

            base.CacheMetadata(metadata);
        }

        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        protected override void Execute(System.Activities.NativeActivityContext context)
        {
            Parameters.Clear();

            Parameters.Add("statusID", ID);
            Parameters.Add("url", Url);
            Parameters.Add("maxWidth", MaxWidth);
            Parameters.Add("hideMedia", HideMedia);
            Parameters.Add("hideThread", HideThread);
            Parameters.Add("omitScript", OmitScript);
            Parameters.Add("align", Align);
            Parameters.Add("related", Related);
            Parameters.Add("lang", Lang);

            base.Execute(context);
        }
    }
}
